package cc.lifepage.server.ai;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;

import java.util.Arrays;

/**
 * $Description
 *
 * @author guojialin
 * @date 2025-06-11 19:59
 */
@SpringBootApplication(scanBasePackages = {
        "cc.lifepage.server"
})
@Slf4j
public class LifePageAiApplication extends SpringBootServletInitializer implements CommandLineRunner  {
    public static String activeProfile;
    @Autowired
    private ApplicationContext appContext;

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        log.info("....................configure.........................");
        return builder.sources(LifePageAiApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(LifePageAiApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        String[] beans = appContext.getBeanDefinitionNames();
        Arrays.sort(beans);
        for (String bean : beans) {
            log.debug("bean:" + bean);
        }
        configureBase();
    }

    private void configureBase() {
        String[] activeProfiles = appContext.getEnvironment().getActiveProfiles();
        for (String profile : activeProfiles) {
            activeProfile = profile;
            log.info("Spring Boot 使用profile为:{}", profile);
        }
    }
}